package com.nhjf.dao.teachers;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.nhjf.common.util.StringUtil;
import com.nhjf.dao.BaseDao;
import com.nhjf.model.teachers.ArtPictures;
import com.nhjf.pojo.qo.teachers.ArtPicturesQo;

@Repository
public class ArtPicturesDao extends BaseDao<ArtPictures, ArtPicturesQo>{

	@Override
	protected Criteria buildCriteria(Criteria criteria, ArtPicturesQo qo) {
		// TODO Auto-generated method stub
		if(qo!=null) {
			criteria.setFetchMode("user", qo.isSeachUser()?FetchMode.JOIN:FetchMode.SELECT);	
			if(qo.getUserId()!=null) {
				criteria.add(Restrictions.eq("user.id",qo.getUserId()));
			}
			if(StringUtils.isNotBlank(qo.getArtName())) {
				criteria.add(Restrictions.eq("artName",qo.getArtName()));
			}
			if(qo.getArtPicturesId()!=null) {
				criteria.add(Restrictions.eq("id",qo.getArtPicturesId()));
			}
			if(StringUtils.isNotBlank(qo.getArtPicturesUrl())) {
				criteria.add(Restrictions.eq("artName",qo.getArtName()));
			}
			if(qo.getUserType()!=null) {
				criteria.add(Restrictions.eq("userType",qo.getUserType()));
			}
			if(qo.getWidth()!=null) {
				criteria.add(Restrictions.eq("width",qo.getWidth()));
			}
			if(qo.getHeight()!=null) {
				criteria.add(Restrictions.eq("height",qo.getHeight()));
			}
		}
		return criteria;
	}

	@Override
	protected Class<ArtPictures> getEntityClass() {
		// TODO Auto-generated method stub
		return ArtPictures.class;
	}

}
